<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta charset="utf-8">
  <title><!--{$lang.page.index.title}--></title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="/static/lay/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="/static/lay/layui/index.css" media="all">
</head>
<body>
<div >
    <div class="layui-text-item" style="text-align: center;"><b><!--{$lang.page.public.control}--></b></div>
     <div class="layui-card">
      <div class="layui-form layuiadmin-card-header-auto">
        <div class="layui-text-item">
          <div class="layui-text-line">
            <label class="layui-text-label"><!--{$lang.page.table.name}--></label>
            <div class="layui-text-inline">
              <!--{$datainfo.title}-->
            </div>
          </div>
          <div class="layui-text-line">
            <label class="layui-text-label"><!--{$lang.page.table.money}--></label>
            <div class="layui-text-inline">
              <!--{$datainfo.fixmoney}-->
            </div>
          </div>
          <div class="layui-text-line" <!--{if $datainfo.timetype eq 2}-->style="display: none;"<!--{/if}-->>
            <label class="layui-text-label"><!--{$lang.page.table.time}--></label>
            <div class="layui-text-inline">
              <!--{$datainfo.fixtime}-->
            </div>
          </div>
          <div class="layui-text-line">
            <label class="layui-text-label"><!--{$lang.page.table.agent}--></label>
            <div class="layui-text-inline">
              <!--{$datainfo.username}-->
            </div>
          </div>
          <div class="layui-text-line">
            <label class="layui-text-label"><!--{$lang.page.table.status}--></label>
            <div class="layui-text-inline">
              <!--{if $datainfo.status==1}-->
              <button class="layui-btn layui-btn-xs" type="button"><!--{$lang.page.table.normal}--></button>
              <!--{elseif $datainfo.status==2}-->
              <button class="layui-btn layui-btn-green layui-btn-xs" type="button"><!--{$lang.page.table.finish}--></button>
              <!--{elseif $datainfo.status==3}-->
              <button class="layui-btn layui-btn-primary layui-btn-xs" type="button"><!--{$lang.page.table.close}--></button>
              <!--{/if}-->
            </div>
          </div>
          <div class="layui-text-line">
            <label class="layui-text-label"><!--{$lang.page.table.notes}-->：</label>
            <div class="layui-text-inline">
              <!--{$datainfo.description}-->
            </div>
          </div>
           <div class="layui-text-line">
            <label class="layui-text-label"><!--{$lang.page.table.regula}-->：</label>
            <div class="layui-text-inline">
              <b style="font-size: 16px; color:#2774ad"><!--{if $datainfo.auto eq 1}--><!--{$datainfo.relatename}--><!--{else}--><!--{$datainfo.title}--><!--{/if}--></b>
            </div>
          </div>
        </div>

      </div>
     </div>
    </div>
  <div class="layui-fluid"  style="padding:0px;">
    <div class="layui-card">
      <div class="layui-card-body">
        <form name="addItem" method="post" lay-filter="component-form-group" class="layui-form">

          <div class="layui-card-body" style="padding: 0">
              <table id="datalist" lay-filter="datalist"></table>
                <script type="text/html" id="toolbartop">
                  <input type="hidden" value="<!--{$datainfo.id}-->" name="id">
                  <input type="hidden" value="<!--{$datainfo.aid}-->" name="aid">
                  <input type="hidden" value="<!--{$datainfo.title}-->" name="title">
                  <input type="hidden" value="<!--{$datainfo.sn}-->" name="sn">
                  <input type="hidden" value="<!--{$datainfo.id}-->" name="operate_id">
                  <input type="hidden" value="<!--{$datainfo.proid}-->" name="proid">
                  <input type="hidden" value="<!--{$datainfo.run}-->" name="run">
                  <input type="hidden" value="<!--{$datainfo.rundisk.sn}-->" name="runsn">
                  <button class="layui-btn layui-btn-sm" lay-event="redatalist"><!--{$lang.page.public.refresh}--></button>
                  <button type="button" id="delall" class="layui-btn showfk layui-btn-sm" lay-submit lay-filter="delall"><!--{$lang.page.public.clear}--></button>
                  <div class="layui-inline showfk">
                      <input type="text" name="conuts" class="layui-input" lay-verify="conuts">
                  </div>
                  <div class="layui-inline showfk" >
                    <button class="layui-btn  layui-btn-sm" type="button" id="submit" lay-submit lay-filter="submit"><!--{$lang.page.public.add}--> <!--{$lang.page.table.venue}--></button>
                  </div>
                  <div class="layui-inline">
                    <input type="radio" name="auto" lay-filter="brickType" value="1" title="<!--{$lang.page.table.auto}--><!--{$lang.page.table.set}-->" <!--{if $datainfo.auto eq 1}--> checked<!--{/if}-->>&nbsp;&nbsp;<input type="radio" name="auto" lay-filter="brickType" value="2" title="<!--{$lang.page.table.noauto}--><!--{$lang.page.table.set}-->" <!--{if $datainfo.auto eq 2}--> checked<!--{/if}-->>
                  </div>

                  <div class="layui-inline">
                    <label class="layui-form-label"><b style="font-size: 14px; color:#e23f00"><text id="sntitle"></text></b></label>
                    <div class="layui-btn layui-btn-danger layui-btn-sm" id="timer" endtime="<!--{$datainfo.endtime}-->" ><!--{$lang.page.public.gorun}--></div>
                    <button class="layui-btn layui-btn-sm" style="float: left; display: none" id="rebtton" type="button" onClick="window.location.reload();"><!--{$lang.page.public.reget}--></button>
                  </div> 
                </script>
                <script type="text/html" id="zizeng">{{d.LAY_TABLE_INDEX+1}}</script>
                <script type="text/html" id="bartool">
                  <a class="layui-btn layui-btn-danger layui-btn-xs control" id="control{{d.id}}" onClick="xadmin.open({title:'<!--{$lang.page.public.control}-->',url:'showcontrol?id={{d.id}}', width:'1200px',height:'620px'});"><!--{$lang.page.public.control}--></a>
                  <div class="layui-btn layui-btn-disabled layui-btn-xs control" id="finish{{d.id}}"><!--{$lang.page.table.finish}--></div>
                  <div class="layui-btn layui-btn-xs control await{{d.id}}" id="timers"><!--{$lang.page.public.gorun}--></div>
                </script>
          </div>        
          <div class="layui-form-item layui-layout-admin">
            <div>
              <div class="layui-footer" style="left: 0;">
                <button type="button" class="layui-btn layui-btn-primary" onClick="xadmin.close();" ><!--{$lang.page.table.back}--></button>
              </div>
            </div>
          </div>
        </form>
      </div>
    </div>
  </div>
<script src="/static/lay/layui/layui.js"></script>
  <script type="text/javascript">
    layui.config({
     base: '/static/lay/' //静态资源所在路径
   }).extend({
     xadmin: 'lib/xadmin' //弹窗
     , lang:'lib/lang'
   }).use(['jquery', 'layer','xadmin', 'form', 'element', 'table', 'lang'], function(){
    var $ = layui.$ //引用jq
    var layer = layui.layer; //独立版的layer无需执行这一句
    var form = layui.form;
    var table = layui.table;
    var lang=layui.lang.init();
    form.render(null, 'component-form-group');
     /* 自定义验证规则 */
    form.verify({
      title: function(value){
        if(value.length < 1){
          return '<!--{$lang.page.table.name}--> <!--{$lang.page.public.nocontent}-->';
        }
      }
    });

    table.render({
            elem: '#datalist'
            , height: 'auto'
            , url: 'disklist' //数据接口
            , method: 'post'
            , page: true //开启分页
            , limit: 10
            , where:{'operateid':<!--{$datainfo.opeid}-->}
            , toolbar: '#toolbartop'
            , defaultToolbar: ['filter', 'exports', 'print']
            , cols: [[ //表头
                {field: 'zizeng', title: function(){ return lang.serial }, align: "center", fixwidth: true, width: 80, templet:'#zizeng'},
                {field: 'sn', title: 'FN',templet: function(d){
                    if(d.status < 2){
                      return '<div>'+d.sn+'</div>';
                    }else{
                      return '<div class="layui-disabled">'+d.sn+'</div>';
                    }
                  }
                },
                // {field: 'robotnum', title: function(){ return lang.robot },templet: function(d){
                //     if(d.status < 2){
                //       return '<div>'+d.robotnum+'</div>';
                //     }else{
                //       return '<div class="layui-disabled">'+d.robotnum+'</div>';
                //     }
                //   }
                // },
                // {field: 'win', title: function(){ return lang.winloss }, templet: function(d) {
                //     text = '<input type="radio" name="win['+(d.LAY_TABLE_INDEX+1)+']" value="1" title="'+lang.upwin+'" ';
                //     if (d.win == 1){ text += ' checked '; }
                //     if (d.status < 2) { text += 'class="layui-input"'; }else{ text += 'class="layui-input layui-disabled" disabled'; }
                //     text += '/>&nbsp;&nbsp;';
                //     text += '<input type="radio" name="win['+(d.LAY_TABLE_INDEX+1)+']" value="2" title="'+lang.downwin+'" ';
                //     if (d.win == 2){ text += ' checked '; }
                //     if (d.status < 2) { text += 'class="layui-input"'; }else{ text += 'class="layui-input layui-disabled" disabled'; }
                //     text += '/>';
                //     return text;
                //   }
                // },
                {field: 'endtime', title: function(){ return lang.endtime }, templet: function(d){
                    var date = new Date(d.endtime*1000); // 假设d.createTime是时间戳
                    if(d.status < 2){
                      return '<div>'+layui.util.toDateString(date, 'yyyy-MM-dd HH:mm:ss')+'</div>';
                    }else{
                      return '<div class="layui-disabled">'+layui.util.toDateString(date, 'yyyy-MM-dd HH:mm:ss')+'</div>';
                    }
                  }
                },
                // {field: 'ordernum', title: function(){ return lang.order+lang.number }, templet: function(d){
                //     if( d.status < 2){
                //       return '<div>'+d.ordernum+'</div>';
                //     }else{
                //       return '<div class="layui-disabled">'+d.ordernum+'</div>';
                //     }
                //   }
                // },
                {fixed: '', title: function(){ return lang.operation }, width: 360, align: 'left', toolbar: '#bartool'}
            ]],
            done: function(d) {
                layer.closeAll('loading');
                auto = $('input[name="auto"]:checked').val();
                runsn = $('input[name="runsn"]').val();
                aid = $('input[name="aid"]').val();
                $('.control').hide();
                $('.await').hide();
                $('.showfk').hide();
                $(document).ready(function() {
                    eval(d.data).forEach((item)=>{
                      if((auto == 2 || aid<1 ) && item.status < 2){$('#control'+item.id).show();}
                      if(item.ordernum>0){$('#order'+item.id).show();}
                      if(item.status==2){$('#finish'+item.id).show();}
                      if(item.sn == runsn){ $('.await'+item.id).show();}
                    })
                })
                if(auto == 2 ){ $('.showfk').show();}
                $('#sntitle').text(lang.nowsn+'：'+ $('input[name="sn"]').val());
            }
    });
    table.on('toolbar(datalist)', function(obj){
      switch(obj.event){
        case 'redatalist':
          //执行重载
          table.reload('datalist');
          break;
      };
    });     
    form.on('submit(submit)', function (data) {
          $('#submit').attr("disabled",true);
          $('#submit').addClass('layui-btn-disabled');
              $.post('#',data.field,function(res){
                  if(res.code == 200){
                      layer.msg(res.msg);
                      setTimeout(() => {
                          window.location.reload();
                          // xadmin.close();
                      }, 1000);
                  }else{
                    $('#submit').removeAttr("disabled");
                    $('#submit').removeClass('layui-btn-disabled');
                    layer.msg(res.msg);
                  }
              })
        return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
    });

    form.on('radio(brickType)', function(data){
        var p = data.value;
        if( p == 1 ){
            $('.showfk').hide(); 
        }else if( p == 2 ){
            $('.showfk').show();
        }
        form.render();
        $.post('operatesave',{
          'id':$('input[name="id"]').val(),
          'auto':p
        },function(res){
            if(res.code == 200){
                layer.msg(res.msg);
                setTimeout(() => {
                    window.location.reload();
                    // xadmin.close();
                }, 1000);
            }else{
                layer.msg(res.msg);
            }
        })
    });
    
    form.on('submit(delall)', function (data) {
        if(data.field.run==1){
            layer.alert('<!--{$lang.page.public.conwarn}-->', {
                offset:'100px'
                , closeBtn: 1 // 是否显示关闭按钮
                , anim: 1 //动画类型
                , btn: ['<!--{$lang.page.table.confirm}-->', '<!--{$lang.page.table.cancel}-->'] //按钮
                , icon: 6 // icon
                , yes: function () {
                    $('#delall').attr("disabled",true);
                    $('#delall').addClass('layui-btn-disabled');
                    $.post('riskdel',data.field,function(res){
                        if(res.code == 200){
                            layer.msg(res.msg);
                            setTimeout(() => {
                                window.location.reload();
                                // xadmin.close();
                            }, 1000);
                        }else{
                          $('#delall').removeAttr("disabled");
                          $('#delall').removeClass('layui-btn-disabled');
                          layer.msg(res.msg);
                        }
                    })
                }
            });
        }else{
             $('#delall').attr("disabled",true);
             $('#delall').addClass('layui-btn-disabled');
             $.post('riskdel',data.field,function(res){
                if(res.code == 200){
                    layer.msg(res.msg);
                    setTimeout(() => {
                        window.location.reload();
                        // xadmin.close();
                     }, 1000);
                }else{
                    $('#delall').removeAttr("disabled");
                    $('#delall').removeClass('layui-btn-disabled');
                    layer.msg(res.msg);
                }
            })
          }
        return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
    });
    $('#timer').ready(function(){
      // if(document.getElementById("timer")!=null){
        var rebtton = document.getElementById("rebtton");
        var endtime =  $('#timer').attr('endtime');
        if(endtime>0){
          let setInt=setInterval(() => {
              var countdownElement = document.getElementById("timer");
              var countdownElements = document.getElementById("timers");
              var now = new Date().getTime(); // 当前时间
              var distance = Math.floor((endtime*1000 - now)/1000); // 距离结束日期还有多少时间
              if(distance<0){
                if(Math.abs(distance)<10){ 
                  window.location.reload();
                }else{
                  clearInterval(setInt); // 如果已经到达或超过了结束日期，清除定时器并隐藏倒计时元素
                  countdownElement.style.display = "none";
                  rebtton.style.display = "block";
                }
                return;
              }else{
                showtime = distance>0?distance:0;
                countdownElement.innerText = "<!--{$lang.page.public.countdown}-->：" + showtime + "s"; // 更新倒计时内容
                if(countdownElements!=null){
                    countdownElements.innerText = "<!--{$lang.page.public.countdown}-->：" + showtime + "s"; // 更新倒计时内容
                }
                return;
              }
          },1000)
        }else{
          countdownElement.style.display = "none";
      }  
    });

  });

  </script>
</body>
</html>

